﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boggle;
using Common.DataStructures;
using Moq;
using NUnit.Framework;

namespace BoggleUnitTests
{
    [TestFixture]
    public class BoggleSolverTests
    {

        public class SolveMethod
        {
            private readonly List<String> _expectedSolutions = new List<string>
                {
                    "abed",
                    "aero",
                    "aery",
                    "bade",
                    "bead",
                    "bread",
                    "bore",
                    "bored",
                    "bred",
                    "broad",
                    "byroad",
                    "derby",
                    "orbed",
                    "orby",
                    "oread",
                    "read",
                    "road",
                    "robe",
                    "robed",
                    "verb",
                    "very",
                    "yore"
                };

            [Test]
            public void SimpleDictionary()
            {
                var dictionaryMock = new Mock<IBoggleDictionary>();
                dictionaryMock.Setup(dictionary => dictionary.Search(It.IsAny<String>()))
                    .Returns((string word) =>
                    {
                        if (_expectedSolutions.Contains(word))
                        {
                            return SearchResult.FullMatch;
                        }
                        return _expectedSolutions.Any(solution => solution.StartsWith(word)) ? SearchResult.PartialMatch : SearchResult.NoMatch;
                    });
                BoggleBoard board = new BoggleBoard(3, 3, new [] { "y", "o", "x", "r", "b", "a", "v", "e", "d" });
                BoggleSolver solver = new BoggleSolver(dictionaryMock.Object);
                IEnumerable<BoggleTraversal> solutions = solver.Solve(board);
                Assert.That(solutions.Select(solution => solution.ToString()), Is.EquivalentTo(_expectedSolutions));
            }
        }
    }
}
